/*
 * @lc app=leetcode.cn id=2485 lang=cpp
 *
 * [2485] 找出中枢整数
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int pivotInteger(int n)
    {
        int x = sqrt((n * n + n) / 2);
        int sum2 = x * (x + 1) / 2;
        int sum1 = (n + x) * (n - x + 1) / 2;
        if (sum2 == sum1)
            return x;
        return -1;
    }
};
// @lc code=end
